import { AppModel } from '../../../../model/AppModel';
import { createUIWidgetMenu } from '../BlockPackage'

export default {

    category: Blockly.Categories.bepart ,
    
    color: [
        Blockly.Colours.operators.primary,
        Blockly.Colours.operators.secondary,
        Blockly.Colours.operators.tertiary
    ] ,

    previousStatement: true ,
    nextStatement: true ,

    init(model: AppModel) {
        this.appendDummyInput()
            .appendField("UI")
            .appendField(createUIWidgetMenu(model, null, ["setText"]), 'uitext')
            .appendField("本文为:")

        this.appendValueInput("what")
    } ,

    coder: {
        JavaScript(block: any, coder: any, model: AppModel) {
            let wid = block.getFieldValue('uitext')
            let widget = model.ui.mapWidgets[wid]
            if(!widget) {
                return ""
            }
            let content = coder.valueToCode(block, "what", coder.ORDER_ASSIGNMENT) || '""'
            return `${coder.indentString()}be.ui.set("${widget.name}", "setText", ${content})\n`
        }
    }
}
